import React, {FC, useEffect} from 'react';
import {Redirect} from "react-router-dom";
import {selectLoginSucInfo} from '../models/GlobalSlice';
import {useSelector} from "react-redux";

interface LoginValidateWrapperProps {
}

const LoginValidateWrapper: FC<LoginValidateWrapperProps> = (props) => {
    const {children} = props;
    const loginSucInfo = useSelector(selectLoginSucInfo);
    useEffect(() => {
        console.log('LoginValidateWrapper 组件挂载完毕!');
    }, []);

    console.log('LoginValidateWrapper 组件render!', props, loginSucInfo);
    if (loginSucInfo) {
        return <>{children}</>
    }
    return (
        <><Redirect to={'/login'}></Redirect></>
    );
};

export default LoginValidateWrapper;
